package com.example.works;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Ex03_Intent extends AppCompatActivity implements View.OnClickListener {

    private RadioGroup rg_01;
    private String height;
    private String weight;
    private String sex;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ex03_intent);

        //我也不知道这个RadioGroup要放在button点击事件的外边, 放里面就空值
        rg_01 = findViewById(R.id.rg_01);
        rg_01.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.rg_rb_01) {
                    sex = "man";
                } else {
                    sex = "woman";
                }
            }
        });

        findViewById(R.id.btn_01).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_01) {
            //获取页面数据, 不在这里做计算
            EditText et_01 = findViewById(R.id.et_01);
            height = et_01.getText().toString();
            EditText et_02 = findViewById(R.id.et_02);
            weight = et_02.getText().toString();


            //跳转并传输bundle
            Intent intent = new Intent(this,EX03_Intent_02.class);
            Bundle bundle = new Bundle();
            bundle.putString("sex",sex);
            bundle.putString("height",height);
            bundle.putString("weight",weight);
            intent.putExtras(bundle);
            startActivity(intent);
        } else {
            Toast.makeText(this,"啊咧?按钮出错了",Toast.LENGTH_SHORT).show();
        }
    }
}